<template>
    <div>
        <el-table :data="getUser" border style="width: 100%">
            <el-table-column prop="uid" label="用户编号" width="280">
            </el-table-column>
            <el-table-column prop="username" label="用户名称" width="180">
            </el-table-column>
            <el-table-column prop="rolename" label="所属角色" width="180">
            </el-table-column>
            <el-table-column label="状态" width="180">
                <template slot-scope="item">
                    <div>
                        <el-button type="success" plain size="mini">{{ item.row.status == 1 ? '正常' : '禁用' }}</el-button>
                        
                    </div>
                </template>
            </el-table-column>
            <el-table-column label="操作" width="260">
                <template slot-scope="item">
                    <div>
                        <el-button type="primary" icon="el-icon-edit" plain size="mini"
                            @click="edit(item.row.uid)">编辑</el-button>
                        <el-button type="danger" icon="el-icon-delete" plain size="mini"
                            @click="del(item.row.uid)">删除</el-button>
                    </div>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination background layout="prev, pager, next" :page-size="getpageSize"  @current-change="pager" :total="total">
        </el-pagination>
    </div>
</template>
<script>
import { userdelete } from '../../request/api'
import { mapGetters } from 'vuex'
export default {
    data() {
        return {
        }
    },
    methods: {
        // 编辑管理员  显示弹框，传一个uid
        edit(uid) {
            this.$emit('canedit', uid)
        },
        // 删除管理员
        del(uid) {
            this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                userdelete({ uid })
                    .then(res => {
                        if (res.code == 200) {
                            this.$message.success(res.msg)
                            this.$store.dispatch('user/GetUserInfo')
                            this.$store.dispatch('user/GetUserCount')
                        }
                    })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });
        },
        // 点击页码切换
        pager(e) {
            this.$store.dispatch('user/changePage', e)
        },
    },
    mounted() {
        // console.log(this.$store);
        // 调用管理员列表和总条数
        this.$store.dispatch('user/GetUserInfo');
        this.$store.dispatch('user/GetUserCount')

    },
    computed: {
        ...mapGetters({
            getUser: 'user/getUser',
            getpageSize: 'user/getpageSize',
            total:'user/getCount'
        }),
    },
    watch: {
    },
    components: {}
}
</script>
<style scoped>
.el-pagination {
    position: absolute;
    right: 15px;
}
</style>